///////////////////////////////////////////////////////////////////////////////////////////
//general scripts
///////////////////////////////////////////////////////////////////////////////////////////
function RemoveText(id, txt)
{	
	if($("#"+id).val() == txt)
	{
		$("#"+id).val('');
		$("#"+id).css('color', 'black');
	}
}

function ReturnText(id, txt)
{
	if($("#"+id).val() == '')
	{
		$("#"+id).val(txt);
		$("#"+id).css('color', 'gray');		
	}
}


///////////////////////////////////////////////////////////////////////////////////////////
//welcome page scripts
///////////////////////////////////////////////////////////////////////////////////////////
/*function OpenLogin()
	{				
		document.all.loginDiv.style.visibility = 'hidden'; 
		document.all.loginForm.style.visibility = '';
		document.all.loginForm.style.height = 'auto';
		document.all.loginForm.style.width = '250px';
	}
	function OpenRegister()
	{
		document.all.loginDiv.style.visibility = 'hidden';
		document.all.loginForm.style.visibility = 'hidden';
		document.all.loginForm.style.height = '0px';
		document.all.loginForm.style.width = '0px';
		document.all.registerForm.style.visibility = '';
		document.all.registerForm.style.height = 'auto';
		document.all.registerForm.style.width = '250px';
	}
	function getRandomImages(limit) {
	    // make request to the server
	    $.getJSON('C:\inetpub\wwwroot\Urban Dynamics\php classes\Login.php', {limit: limit}, function(data) {
	        // data is now an array with all the images
	        $.each(data, function(i) {
		        alert('boo ' + data[i]);
	            
	        });
	    });
	}
*/
///////////////////////////////////////////////////////////////////////////////////////////
//Panes page scripts
///////////////////////////////////////////////////////////////////////////////////////////
	var ContentHeight = 140;
	var TimeToSlide = 250.0;
	
	var openAccordion = '';

	function resizeFrame(f) 
	{
		//if(f.contentWindow.document.body.scrollHeight > window.innerHeight)
		{
			f.style.height = (window.innerHeight - 200) + "px";
		}
		//else
		{
			//f.style.height = window.innerHeight + "px";
		}
	}
	
	function runAccordion(index)
	{
	  var nID = "Accordion" + index + "Content";
	  if(openAccordion == nID)
	    nID = '';
	   
	  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
	      + openAccordion + "','" + nID + "')", 33);
	 
	  openAccordion = nID;
	}
	function animate(lastTick, timeLeft, closingId, openingId)
	{  
	  var curTick = new Date().getTime();
	  var elapsedTicks = curTick - lastTick;
	 
	  var opening = (openingId == '') ? null : document.getElementById(openingId);
	  var closing = (closingId == '') ? null : document.getElementById(closingId);
	 
	  if(timeLeft <= elapsedTicks)
	  {
	    if(opening != null)
	      opening.style.height = ContentHeight + 'px';
	   
	    if(closing != null)
	    {
	      closing.style.display = 'none';
	      closing.style.height = '0px';
	    }
	    return;
	  }
 
	  timeLeft -= elapsedTicks;
	  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
	
	  if(opening != null)
	  {
	    if(opening.style.display != 'block')
	      opening.style.display = 'block';
	    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
	  }
	 
	  if(closing != null)
	    closing.style.height = newClosedHeight + 'px';
	
	  setTimeout("animate(" + curTick + "," + timeLeft + ",'"
	      + closingId + "','" + openingId + "')", 33);
	}

	function ShowProfilePage()
	{
		$('#iFrame').attr('src', './ProfilePage.php');		
	}

	function ShowGroupsPage()
	{
		$('#iFrame').attr('src', './Groups.php');
	}

	function ShowManageGroupPage()
	{
		$('#iFrame').attr('src', './ManageGroups.php');
	}
	
	function ShowInboxPage()
	{
		$('#iFrame').attr('src', './Inbox.php');
	}
	
	function ShowGroup(num)
	{		
		$('#iFrame').attr('src', './Group.php');
	}
	
	function ShowFriend(num)
	{
		$('#iFrame').attr('src', './Friend.php');
	}
///////////////////////////////////////////////////////////////////////////////////////////
//manage groups page scripts	
///////////////////////////////////////////////////////////////////////////////////////////

function OpenHiddenDiv(id)
{
	if($("#"+id).css('visibility') == 'hidden')
	{
		$("#"+id).css('visibility', 'visible');
		$("#"+id).css('display', 'block');
	}
	else
	{
		$("#"+id).css('visibility', 'hidden');
		$("#"+id).css('display', 'none');
	}
	//resize iframe
	window.parent.document.getElementById('iFrame').style.height += $("#"+id).css('height') + 'px';
}

function ShowGroupTab(num)
{
	
	window.parent.document.getElementById('iFrame').src="./Group.php";
}

function shorten(text)
{
	var lngth = 70;
	if (text.length <= lngth)
		return text;
	ind=text.length;
	while((text[ind] != ' ') && (ind >0))
		ind--;
	if (ind == 0)
		return text.substr(0,length) + '..';
	return text.substr(0,ind) + '..';
}
function replaceBR(str)
{
	i= str.length / 2;
	while(i>0)
	{
		tmpstr=str.replace("\n\r","<br>").replace("\n","<br>").replace("\r","<br>");
		if(tmpstr == str) return str;
		str=tmpstr;
		i--;
	}
	return str;
}